/**
 * 
 */
package Monopol.AssetGroups;

import java.awt.Color;
import java.util.ArrayList;
import java.util.Iterator;

import Player.Player;
import Square.Transportation;


/**
 * @author Avia Tam
 * @author Assaf Miron
 *
 */
public class AllTransportations implements AssetGroup {
	
	ArrayList<Transportation>transportations; // All the transportations in the Game

	/**
	 * @param transportations
	 */
	public AllTransportations() {
		super();
		this.transportations = new ArrayList<Transportation>(); // Initialize the Array
		this.transportations.clear(); // Clear the Array
	}
	/**
	 * @return The transportations Array
	 */
	public ArrayList<Transportation>getTransportation() {
		return transportations;
	}

	/**
	 * Add a Transportation to the transportation Array
	 * @param transportation The transportation to be Added
	 */
	public void addTransportation(Transportation transportation) {
		this.transportations.add(transportation);
	}
	
	/**
	 * Creates a New Transportation Object and Adds it to the Transportation Group
	 * @param transName The Transportation Name
	 * @param stayPrice The Stay Price Array
	 * @param cost The Transportation Cost
	 * @return a Transportation Object
	 */
	public Transportation createTransportation(String transName, Double[] stayPrice, Double cost)
	{
		// Create a New Transportation
		Transportation transportation = new Transportation(transName, stayPrice, cost, this);
		// Add this Transportation to the Transportation Group
		this.addTransportation(transportation);
		// Return the Newly Created Transportation
		return transportation;
		
	}
	/* (non-Javadoc)
	 * @see Monopol.AssetGroup#isAllAssetGroupMine(Player.Player)
	 */
	@Override
	public Boolean isAllAssetGroupMine(Player player) 
	{
		// Create an Iterator to run on the Assets Group
		Iterator<Transportation> i = transportations.iterator();		 
		// Create a Temporary boolean variable - Check if all the group is owned by the same Player
		Boolean allGroups = new Boolean(true);
		// Loop the State while all the Cities have the same Owner
		while(i.hasNext() && allGroups)
		{
			// Check the Owner and compare with the Player
			if(i.next().getOwner() != player)
			{
				// Not the Same Owner as Player - Stop Checking
				allGroups = false;
			}
		}
		// Return the Value of All Groups
		return allGroups;
	}
	
	/* (non-Javadoc)
	 * @see Monopol.AssetGroup#getName()
	 */
	@Override
	public String getName() 
	{
		return "All Transportations";
	}
	/* (non-Javadoc)
	 * @see Monopol.AssetGroup#getAssets()
	 */
	@Override
	public ArrayList<?> getAssets() {
		return transportations;
	}
	/* (non-Javadoc)
	 * @see Monopol.AssetGroups.AssetGroup#getColor()
	 */
	@Override
	public Color getColor() {
		// All Transportations are Orange-Red-ish 
		return new Color(248, 134, 101);
	}
}
